home *** CD-ROM | disk | FTP | other *** search
- /* testavl.c - test AVL tree funcs */
-
- #include <stdio.h>
- #include <malloc.h>
- #include "avltree.h"
-
- main(argc, argv)
- int argc; char *argv[]; {
-
- char command[30], *key, *data;
- avl_tree t = NULL, node;
-
- while (1) {
- printf("avl>");
- scanf("%s", command);
-
- /* add command */
-
- if (strcmpi(command, "add") == 0) {
- key = calloc(1, 32);
- data = calloc(1, 80);
- scanf("%s %[^\n]", key, data);
- avl_insert(key, data, &t);
- }
-
- /* view command */
-
- else if (strcmpi(command, "view") == 0)
- sideview(0, t);
-
- /* find command */
-
- else if (strcmpi(command, "find") == 0) {
- key = calloc(1, 32);
- scanf("%s", key);
- node = find_in_tree(key, t);
- if (node == NULL)
- printf("%s not found\n", key);
- else
- printf("%s:%s\n", key, node->avl_data);
- free(key);
- }
-
- /* exit command */
-
- else if (strcmpi(command, "exit") == 0 || feof(stdin))
- exit(0);
-
- else
- fprintf(stderr, "Unknown command %s\n", command);
- }
- }
-